﻿#include "ui/animation.h"



std::map<anip::_bind_notifiable*, anip::ui::Animation::Entry>
    anip::ui::Animation::_entries;

void anip::ui::Animation::_update()
{
    float time = (float)anip::time();
    std::map<_bind_notifiable*, Entry> newEntries;
    for (auto& [var, entry] : _entries)
    {
        var->onChanged();
        if (entry.endTime <= time)
        {
            var->markVolatile(false);
        }
        else
            newEntries[var] = entry;
    }
    std::swap(_entries, newEntries);
}

void anip::ui::Animation::_removeControl(Control& c)
{
    std::map<_bind_notifiable*, Entry> newEntries;
    for (auto& [var, entry] : _entries)
    {
        if (entry.parent != &c)
            newEntries[var] = entry;
    }
    std::swap(_entries, newEntries);
}